using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Sudoku.GamePlay;
using Services;

namespace Sudoku.Menu
{
	public class BoardCreatorScene : ExtendedGameComponent
	{
		Texture2D bg;
		IBoardCreator boardService;

		SpriteFont sudokuCountFont;
		string sudokuCount;
		Vector2 sudokuCountPos;
		Color sudokuCountColor;

		public BoardCreatorScene(Game game)
			: base(game)
		{
			boardService = Game.Services.GetService(typeof(IBoardCreator)) as IBoardCreator;
		}

		public override void Initialize()
		{
			bg = textureService.Background("General");
			sudokuCountFont = fontService.Font(FontType.Delicious26Bold);
			sudokuCount = "";
			sudokuCountPos = new Vector2(220, 400);
			sudokuCountColor = Color.Blue;

			soundService.TurnPageSound();

			var inputService = Game.Services.GetService(typeof(IInputManager)) as IInputManager;
			inputService.OnBack += new InputManager.PhoneButtonEvent(Back);

			base.Initialize();
		}

		#region INPUT

		private void Back()
		{
			soundService.PlaySound(SoundType.Fumble);
			StateManagement.StateManager.StartMenu(Game);
		}

		#endregion

		public override void Update(GameTime gameTime)
		{
			sudokuCount = boardService.NumberOfEvaluatedSudoku().ToString();
			base.Update(gameTime);
		}

		public override void Draw(GameTime gameTime)
		{
			spriteBatch.Begin();
			spriteBatch.Draw(bg, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White);
			spriteBatch.DrawString(sudokuCountFont, sudokuCount, sudokuCountPos, sudokuCountColor);
			spriteBatch.End(); 
			
			base.Draw(gameTime);
		}
	}
}
